// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import realThing from "../../TS/BASE/realThing";
import { gif } from "../../TS/BASE/spineANDgif/gif";
import DL from "../../TS/Ditu/des/DL";
import GeZiManager from "../../TS/Manager/GeZiManager";
import MessageCenter from "../../TS/Message/MessageCenter";
import turn from "../../TS/game/time/turn";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NG extends DL {
DJ:number=2
BZT:number=3
  start(): void {
      turn.Roo.push(this)
  }




  roundPass(): void {
      this.BZT--
      this.node.children[0].getComponent(cc.Label).string=this.BZT.toString()
    if ( this.BZT==0) {
   this.DBZ()
        this.ZHA(this.ZB,-1) 
   this.dead(null)
      }
  }

  dead(r:realThing){ 
   // this.node.active = false; 


   



  this.deadgif();
  setTimeout(() => {
    GeZiManager.shanchu(turn.Roo,this)
  },200);
  }

  BZ(preZB:number)
  {for(let a of GeZiManager.GR){if(a.ZB==this.ZB){a.dead()}}
    MessageCenter.MakeSHMessage("AM",[this.ZB],1,0,"getOneC")

      //  console.log(GeZiManager.Tcharacter.shose.TheNumber)
        if(GeZiManager.Tcharacter&&GeZiManager.Tcharacter.shose&&GeZiManager.Tcharacter.shose.TheNumber=="C01"){GeZiManager.dm-=2}
       
this.playFrameAnimation1("BZ",0,0)
this.dead(null)
this.ObstacleClear();

  }




  ZHA(k,v:number){
    let b=[this.NfindGe(k,2,1),this.NfindGe(k,4,1),this.NfindGe(k,6,1),this.NfindGe(k,8,1)]
    if (this.DJ>3) {
      b=this.getNIGno5(k)
    }
    
    switch (v) {
        case 0:v=3
            
            break;
            case 1:v=2
            
            break;
            case 2:v=1        
            break;
            case 3:v=0
            
            break;
    
        default:v=-1;
            break;
    }
    
    if(v!=-1){b[v]=0}
    
    
    let g=[]
    for (let a of GeZiManager.AllObstacles) {
        if (a instanceof DL&&b.includes(a.ZB)) {
            console.log(a.ZB)   
            a.DBZ();
          console.log(b);console.log(a.ZB)
          for(let c of b){if(c!=0){this.ZHA(c,b.indexOf(c))};}
       g.push(a.ZB);
        }
        }
    
        for (let a of GeZiManager.AllObstacles) {
            if (a instanceof DL&&g.includes(a.ZB)) {
            a.ObstacleClear();
            }
            }
    
    
    






}

DBZ(){
  this.playFrameAnimation1("DBZ",0,0)
  let b=[this.findGe(2,1),this.findGe(4,1),this.findGe(6,1),this.findGe(8,1)]
     if (this.DJ>3) {
    b=this.getNIGno5(this.ZB)
  }
  let k=2
  if (this.DJ>2) {
    k=3
  }
  MessageCenter.MakeSHMessage("AM",b,k,null,"wuli");
  if (this.DJ>4) {
    for(let j of b){
      MessageCenter.MakeSHMessage("AM",j,[this.turn8([this.faceIs(j)])[0],0.4],null,"move");
    }
  }
  this.BZ(this.ZB)
}


playFrameAnimation1(n: string, loop: number, p: number): void {
   /* switch (n) {
      case "BZ":
        this.node.active=true
       
      this.node.children[0].getComponent(gif).moveToNextFrame(7,31,0);
console.log(GeZiManager.Tcharacter.WK)
      setTimeout(()=>{this.node.children[1].getComponent(gif).moveToNextFrame(0,6,0);  
       for(let c of GeZiManager.GR){if (c.ZB==this.ZB) {
        c.JJ();
       }}
        MessageCenter.MakeSHMessage("AM",[this.ZB],3+GeZiManager.dm,0,"wuli") ; ;this.fadeOutAndDisappear(this.node,2500)},800)
    setTimeout(()=>{   this.node.children[2].active=false;},500) 


          break;
 
      default: this.node.children[0].getComponent(gif).moveToNextFrame(16,31,0);   MessageCenter.MakeSHMessage("AM",[this.ZB],3+GeZiManager.dm,null,"wuli") ; ;this.fadeOutAndDisappear(this.node,2500)
      setTimeout(()=>{   this.node.children[2].active=false;},200) 
          break;
    }*/
          MessageCenter.MakeSHMessage("AM",[this.ZB],3+GeZiManager.dm,null,"wuli") ;this.fadeOutAndDisappear(this.node,2500)
         // setTimeout(()=>{   this.node.children[2].active=false;},500) 
      


        }
}